﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace ContraMetal
{
    class Player
    {
        #region Variables
        Texture2D texture;
        Vector2 position,velocity;
        bool hasJump;
        #endregion

        #region Propiedades
        public Texture2D Texture
        {
            get { return texture; }
            set { texture = value; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
        #endregion

        #region Metodos
        public void Load(ContentManager Content)
        {
            texture = Content.Load<Texture2D>("Images/palito");
            position = new Vector2(50,50);
            hasJump = true;
        }

        public void Update(GameTime gameTime)
        {
            position += velocity;
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
                velocity.X = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 5;
            else if (Keyboard.GetState().IsKeyDown(Keys.Left))
                velocity.X = -(float)gameTime.ElapsedGameTime.TotalMilliseconds / 5;
            else velocity.X = 0f;

            //salto
            if (Keyboard.GetState().IsKeyDown(Keys.Up) && hasJump == false)
            {
                position.Y -= 5f;
                velocity.Y = -9f; 
                hasJump = true;
            }

            if (hasJump == true)
            {
                float i = 1;
                velocity.Y += 0.3f * i;
            }

            if (position.Y + texture.Height >= 450)
                hasJump = false;

            if (hasJump == false)
                velocity.Y = 0f;
        }

        public void Draw(SpriteBatch batch)
        {
            batch.Draw(texture, position, Color.White);
        }
        #endregion
    }
}
